package com.bw.liuyushan.liuyushan20210929.MVP.Activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.liuyushan20210929.Entity.UserBean;
import com.bw.liuyushan.liuyushan20210929.MVP.Contrack.IContrackTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Model.BaseModelTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.liuyushan20210929.R;
import com.bw.liuyushan.mvp_lib.View.BaseActivity;

public class UserRegActivity extends BaseActivity<BasePresenterTest> implements IContrackTest.C_ViewTest {


    private android.widget.EditText username2;
    private android.widget.EditText password2;
    private android.widget.EditText repassword;
    private android.widget.Button reg;

    @Override
    public int bindLayout() {
        return R.layout.activity_regmain;
    }

    @Override
    public void initView() {
        //链接 防内存泄露
        mPresenter=new BasePresenterTest(new BaseModelTest(),this);

        username2 = (EditText) findViewById(R.id.username2);
        password2 = (EditText) findViewById(R.id.password2);
        repassword = (EditText) findViewById(R.id.repassword);
        reg = (Button) findViewById(R.id.reg);
    }

    @Override
    public void initDate() {
        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name_reg = username2.getText().toString();
                String pass_reg = password2.getText().toString();
                String repass = repassword.getText().toString();
                if (name_reg.isEmpty()){
                    ToastUtils.showShort("用户名不能为空");
                }else{
                    if (pass_reg.isEmpty()){
                        ToastUtils.showShort("密码不能为空");
                    }else{
                        if (repass.equals(pass_reg)){
                            mPresenter.mpReg(name_reg,pass_reg,repass);
                        }else{
                            ToastUtils.showShort("两次密码不一致");
                        }
                    }
                }
            }
        });

    }

    @Override
    public void ShowReg(UserBean userBean) {
        if (userBean.getErrorCode()==0){
            ToastUtils.showShort("注册成功,跳转登录");
            Intent intent = new Intent(UserRegActivity.this, UesrMainActivity.class);
            startActivity(intent);
        }else{
            ToastUtils.showShort("注册失败");
        }
    }
}
